package com.lagou.blog.controller;

import com.lagou.blog.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Controller
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @RequestMapping("/index")
    public String showArticle(Model model, HttpServletRequest request){
        String pageStr = (String) request.getParameter("page");
        Integer page = 0 ;
        if (pageStr!=null && !pageStr.isEmpty()){
            page = Integer.valueOf(pageStr);
        }
        Map<String,Object> map = articleService.getArticle(page);
        model.addAttribute("list", map.get("list"));
        model.addAttribute("fisrt",map.get("fisrt"));
        model.addAttribute("pre",map.get("pre"));
        model.addAttribute("page",map.get("page"));
        model.addAttribute("next",map.get("next"));
        model.addAttribute("last",map.get("last"));
        return "client/index";
    }
}
